***************
* This script performs descriptive analyses of the recruiter click data
* Author: Daniel Kopp
***************

	clear
	clear matrix
	clear mata
	set more off	
	set maxvar 8000

	use "data_raw\jobroom_data_full_201703_201712.dta"

	****************************
	* Define Globals
	****************************
	
	global skills_dummy_full    "has_skills sk_det_lang0 sk_det_lang1 sk_det_lang2 sk_det_lang3 sk_det_lang4 sk_det_lang_m  sk_exp  sk_education   sk_educ_tert  sk_educ_lehre  sk_educ_weiter sk_softskills sk_it_gen sk_it_deep sk_machines sk_leadership sk_language sk_lgerman sk_lfrench sk_litalian sk_lenglish sk_lchgerman sk_exp_dur_c0 sk_exp_dur_c1 sk_exp_dur_c2 sk_exp_dur_c3 sk_exp_dur_c4 sk_exp_dur_c_m sk_lsoutheuro sk_lother sk_lmiddleeast sk_lbalkan sk_lcentreast sk_lasia skill_country_region1_general skill_country_region2_general skill_country_region3_general skill_country_region4_general skill_country_region5_general skill_country_region6_general skill_country_region8_general skill_country_region9_general" 
	global lang_dummy_full 	"l_German l_CH_German l_English l_French  l_Italian l_northwest	l_southeuro l_centreast l_Balkan l_middleeast l_Asia l_Other l_missing"
	global other_dummy "erfa_s0 erfa_s1 erfa_s2 erfa_s3 erfa_s_m mobility_cat0 mobility_cat1 mobility_cat2 mobility_cat3 mobility_cat4 mobility_cat_m 	limcontract0 limcontract1 limcontract99 verfuegbar0 verfuegbar1 verfuegbar99 no_searchvar no_diff_prof_m 	zuletzt_s abschluss_s0 abschluss_s1 abschluss_s2 abschluss_s3 abschluss_s_m gesch_kontakt Sonn_Feiertag Schichtarbeit Nachtarbeit Heimarbeit Lehre fuehrer_kat0 fuehrer_kat1 fuehrer_kat2 fuehrer_kat3 fuehrer_kat4 fuehrer_kat5 fuehrer_kat6 fuehrer_kat_m education_isced_1 education_isced_2 education_isced_3 education_isced_6 education_isced_7 education_isced_8 education_isced_999 prof_length_1 prof_length_2 prof_length_3 prof_length_4 prof_length_99 user_logged_in"
	global kanton "kanton1 kanton2 kanton3 kanton4 kanton5 kanton6 kanton7 kanton8 kanton9 kanton10 kanton11 kanton12 kanton13 kanton14 kanton15 kanton16 kanton17 kanton18 kanton19 kanton20 kanton21 kanton22 kanton23 kanton24 kanton25 kanton26"
	global lang_region "lang_region1 lang_region2 lang_region3 lang_region4"
	global other_contin " sk_est_n_word no_diff_prof prof_exp_tot"
	global occup_dummy "bn2000_1_s1 bn2000_1_s2 bn2000_1_s3 bn2000_1_s4 bn2000_1_s5 bn2000_1_s6 bn2000_1_s7 bn2000_1_s8 bn2000_1_s9"
	global squared "sk_est_n_word_2 no_diff_prof_2 prof_exp_tot_2"
	global nation_name_kat "nation_kat0 nation_kat1 nation_kat2 nation_kat3 nation_kat4 nation_kat5 nation_kat6 nation_kat8 nation_kat9 nation_kat_m name_kat0 name_kat1 name_kat2 name_kat3 name_kat4 name_kat5 name_kat6 name_kat7 name_kat8 name_kat_m"
	
	* Workvolume variables
	gen workvolume = num_vermittlungs_grad

	gen 	fulltime = workvolume_cat==1
	replace fulltime = . if workvolume_cat==.
	
	***
	* Search criteria selected by recruiters
	***

	gen job_title_ 			= s_job_nr!=.
	gen skills_ 			= s_skills_notes!=.
	gen workplace_ 			= s_workplace_grossregion!=. 
	gen residence_ 			= s_candidate_residence!=.
	gen workvolumen_ 		= s_workload!=.
	gen education_level_ 	= s_education!=.
	gen diploma_origin_ 	= s_diploma!=. 
	gen experience_			= s_experience!=.
	gen drivers_license_ 	= s_drivers_license!=.
	gen type_of_work_		= s_special_type_of_work!=.
	gen availability_		= s_candidate_availability!=.
	gen language_			= s_lang1!=. | s_lang2!=. | s_lang3!=. | s_lang4!=. | s_lang5!=.
	label var job_title_ 			"Job title"
	label var  skills_ 				"Special skills"
	label var  workplace_ 			"Work location" 
	label var  residence_ 			"Place of residence of jobseekers"
	label var  workvolumen_ 		"Work volume"
	label var  education_level_ 	"Education level"
	label var  diploma_origin_ 		"Origin of diploma"
	label var  experience_			"Experience"
	label var  drivers_license_ 	"Drivers license"
	label var  type_of_work_		"Type of work (night/shift work, ...)"
	label var  availability_		"Availability"
	label var  language_			"Language skills"

	gen 	workplace_zh = s_workplace_grossregion==26
	replace workplace_zh = . if s_workplace_grossregion==.
	label var workplace_zh "\quad Zurich"

	gen 	workplace_be = s_workplace_grossregion==4
	replace workplace_be = . if s_workplace_grossregion==.
	label var workplace_be "\quad Bern"

	gen 	workplace_ag = s_workplace_grossregion==1
	replace workplace_ag = . if s_workplace_grossregion==.
	label var workplace_ag "\quad Argovia"

	gen 	diploma_ch   = s_diploma==1 
	replace diploma_ch   = . if s_diploma==.
	label var diploma_ch "\quad CH"

	gen 	diploma_for_r   = s_diploma==2 
	replace diploma_for_r   = . if s_diploma==.
	label var diploma_for_r "\quad Foreign, recognized in CH"

	gen 	diploma_for_nr   = s_diploma==3 
	replace diploma_for_nr   = . if s_diploma==.
	label var diploma_for_nr "\quad Foreign, not recognized in CH"

	gen 	diploma_none   = s_diploma==4 
	replace diploma_none   = . if s_diploma==.
	label var diploma_none "\quad None"

	gen 	s_workload_cat = .
	replace s_workload_cat = 1 if s_workload==10
	replace s_workload_cat = 2 if inrange(s_workload,5,9)
	replace s_workload_cat = 3 if inrange(s_workload,1,4)

	gen 	workhours_full   = s_workload_cat==1 
	replace workhours_full   = . if s_workload_cat==.
	label var workhours_full "\quad Full-time"

	gen 	workhours_50_90   = s_workload_cat==2 
	replace workhours_50_90   = . if s_workload_cat==.
	label var workhours_50_90 "\quad Part-time 50-90\%"

	gen 	workhours_l_50   = s_workload_cat==3 
	replace workhours_l_50   = . if s_workload_cat==.
	label var workhours_l_50 "\quad Part-time $<$ 50\%"

	gen 	avail_imm		= s_candidate_availability==1
	replace	avail_imm		= . if s_candidate_availability==.
	label var avail_imm "\quad Immediately"

	gen 	avail_bya		= s_candidate_availability==2
	replace	avail_bya		= . if s_candidate_availability==.
	label var avail_bya "\quad By arrangement"

	gen 	lang_german		= s_lang1==1 | s_lang2==1 | s_lang3==1 | s_lang4==1 | s_lang5==1 
	replace lang_german		= . if s_lang1==.
	label var lang_german "\quad German"

	gen 	lang_chgerman	= s_lang1==28 | s_lang2==28 | s_lang3==28 | s_lang4==28 | s_lang5==28 
	replace lang_chgerman	= . if s_lang1==.
	label var lang_chgerman "\quad CH-German"

	gen 	lang_french		= s_lang1==2 | s_lang2==2 | s_lang3==2 | s_lang4==2 | s_lang5==2 
	replace lang_french		= . if s_lang1==.
	label var lang_french "\quad French"

	gen 	lang_english	= s_lang1==5 | s_lang2==5 | s_lang3==5 | s_lang4==5 | s_lang5==5 
	replace lang_english	= . if s_lang1==.
	label var lang_english "\quad English"

	gen 	exp1			= s_experience==1
	replace exp1			= . if s_experience==.
	label var exp1 "\quad $<$ 1 year"

	gen 	exp1_3			= s_experience==2
	replace exp1_3			= . if s_experience==.
	label var exp1_3 "\quad 1-3 years"

	gen 	exp4f			= s_experience==3
	replace exp4f			= . if s_experience==.
	label var exp4f "\quad $>$ 3 years"

	gen  points1 = .
	label var points1 "\quad  ...."

	gen  points2 = .
	label var points2 "\quad  ...."

	preserve
	collapse job_title_ skills_ workplace_ residence_ workvolumen_ education_level_ diploma_origin_ experience_ drivers_license_ type_of_work_ availability_ language_ workplace_zh workplace_be workplace_ag diploma_ch diploma_for_r diploma_for_nr diploma_none workhours_full workhours_50_90 workhours_l_50 avail_imm avail_bya lang_german lang_chgerman lang_french lang_english exp1 exp1_3 exp4f points1 points2, by(search_tag)

	estpost sum job_title_ skills_ workplace_ residence_ workvolumen_ education_level_ diploma_origin_ experience_ drivers_license_ type_of_work_ availability_ language_
	estadd matrix pc = e(mean)*100
	eststo est1
	estpost sum workplace_zh workplace_be workplace_ag points1 diploma_ch diploma_for_r diploma_for_nr diploma_none workhours_full workhours_50_90 workhours_l_50 avail_imm avail_bya lang_german lang_chgerman lang_french lang_english points2 exp1 exp1_3 exp4f
	estadd matrix pc = e(mean)*100
	eststo est2
	restore

	esttab est1 est2, cells(pc(fmt(%9.1f))) varwidth(30) label varlabels(`e(labels)')  collabels(none) transform(@*100 100) noobs ///
		order(job_title_ residence_ workplace_ workplace_zh workplace_be workplace_ag points1 diploma_origin_ diploma_ch diploma_for_r diploma_for_nr diploma_none workvolumen_  workhours_full workhours_50_90 workhours_l_50 language_ lang_german lang_chgerman lang_french lang_english points2 availability_ avail_imm avail_bya  experience_ exp1 exp1_3 exp4f drivers_license_  skills_ education_level_ type_of_work_) ///
		mtitle("Share selected" "Share within category")
	esttab est1 est2 using "$results_part_time/table_d2.tex", replace ///
	 cells(pc(fmt(%9.1f))) varwidth(30) label varlabels(`e(labels)')  collabels(none) transform(@*100 100) noobs frag ///
		order(job_title_ residence_ workplace_ workplace_zh workplace_be workplace_ag points1 diploma_origin_ diploma_ch diploma_for_r diploma_for_nr diploma_none workvolumen_  workhours_full workhours_50_90 workhours_l_50 language_ lang_german lang_chgerman lang_french lang_english points2 availability_ avail_imm avail_bya  experience_ exp1 exp1_3 exp4f drivers_license_  skills_ education_level_ type_of_work_) ///
		mtitle("Share selected" "Share within category") ///
		substitute(" ." "")

	
	****************************
	* How many stes are unemployed (received at least once unemployment benefits)?
	****************************
	
	preserve
	collapse first_month_taggeld , by(stes_id)
	tab first_month_taggeld,m		// 79% claimed unemployment benefits
	restore

	****************************
	* Gen Isco-3 and Isco-2 digit variable for last occupation
	****************************
	
	* Transformation into isco08 3-digit
	gen isco_08_4_last_string=string(isco_08_4_last)
	gen isco_08_3_last=substr(isco_08_4_last_string,1,3)
	destring isco_08_3_last, replace
	drop isco_08_4_last_string
	label values isco_08_3_last isco08_3_lab	

	* Transformation into isco08 2-digit
	gen isco_08_3_last_string=string(isco_08_3_last)
	gen isco_08_2_last=substr(isco_08_3_last_string,1,2)
	destring isco_08_2_last, replace
	drop isco_08_3_last_string
	label values isco_08_2_last isco08_2_lab	

	tab isco_08_2_last, m // 38 different occupations (without armed forces). Only 63	"Subsistence farmers, fishers, hunters and gatherers" 94	"Food preparation assistants" missing

			
	****************************	
	* Gen variable for searches in which recruiters restrict results to full-/part-time workers 
	****************************	
	
	tab s_workload,m nol
	gen s_full 			= s_workload==10
	gen s_part 			= inrange(s_workload,1,9)
	gen s_noworkload 	= s_workload==.
	
	* Gen parttime dummy
	gen 	parttime = inrange(workvolume_cat,2,3)
	replace parttime = . if workvolume_cat==.

		
	********************************		
	* Distribution of searches and candidates by occupation
	********************************
	
	* Gen isco 1-digit last occupation of a candidate
	
	tab isco_08_2_last, m
	recode isco_08_2_last (10=99) (20=99) (30=99) (50=99) (70=99) (80=99) (90=99)
	
	cap gen isco_08_1_last = .
	replace isco_08_1_last = 1 if inrange(isco_08_2_last,11,14)
	replace isco_08_1_last = 2 if inrange(isco_08_2_last,21,26)
	replace isco_08_1_last = 3 if inrange(isco_08_2_last,31,35)
	replace isco_08_1_last = 4 if inrange(isco_08_2_last,41,44)
	replace isco_08_1_last = 5 if inrange(isco_08_2_last,51,54)
	replace isco_08_1_last = 6 if inrange(isco_08_2_last,61,64)
	replace isco_08_1_last = 7 if inrange(isco_08_2_last,71,75)
	replace isco_08_1_last = 8 if inrange(isco_08_2_last,81,83)
	replace isco_08_1_last = 9 if inrange(isco_08_2_last,91,96)
	replace isco_08_1_last = 0 if inrange(isco_08_2_last,01,03)
	cap label drop isco08_1_lab
	cap run "Help_files\label_isco08_1.do"
	label values isco_08_1_last isco08_1_lab
		
	recode isco_08_1_last (.=0) 						// we recode missing values as zero (unknown), otherwise we loose too many observations
			
	tab isco_08_1_last, m


	* Gen isco 1-digit occupation of a recruiter search
	
	tab s_isco_08_2
	recode s_isco_08_2 (10=99) (20=99) (30=99) (50=99) (70=99) (90=99)
	
	gen s_isco_08_1 = .
	replace s_isco_08_1 = 1 if inrange(s_isco_08_2,11,14)
	replace s_isco_08_1 = 2 if inrange(s_isco_08_2,21,26)
	replace s_isco_08_1 = 3 if inrange(s_isco_08_2,31,35)
	replace s_isco_08_1 = 4 if inrange(s_isco_08_2,41,44)
	replace s_isco_08_1 = 5 if inrange(s_isco_08_2,51,54)
	replace s_isco_08_1 = 6 if inrange(s_isco_08_2,61,64)
	replace s_isco_08_1 = 7 if inrange(s_isco_08_2,71,75)
	replace s_isco_08_1 = 8 if inrange(s_isco_08_2,81,83)
	replace s_isco_08_1 = 9 if inrange(s_isco_08_2,91,96)
	replace s_isco_08_1 = 0 if inrange(s_isco_08_2,01,03)
	cap label drop isco08_1_lab
	run "Help_files\label_isco08_1.do"
	label values s_isco_08_1 isco08_1_lab
	
	recode s_isco_08_1 (.=0) 						// we recode missing values as zero, otherwise we loose too many observations
		
	* Save share of women in search results (count every search only once)
	capture bysort search_tag: 	gen 	n = _n
	capture bysort search_tag: 	gegen female_share_search = mean(geschlecht)	
	capture bysort s_isco_08_2: gegen female_share_isco_ws_temp = mean(female_share_search) 		if n ==1
	capture bysort s_isco_08_2: gegen female_share_isco_ws 		= mean(female_share_isco_ws_temp)
	drop n 
	
	* Gen var for the number of searches 
	capture bysort s_isco_08_2: egen searches_peroccup_isco = nvals(search_tag)
	 
	preserve
		fcollapse (mean) female_share_isco_ws searches_peroccup_isco s_isco_08_1 , by(s_isco_08_2)
		label var female_share_isco_ws "Female share in search list (unweighted)"
		save "Misc_files\isco_share_female.dta", replace
	restore 
	
	* Occupations by candidates
	preserve
	bysort isco_08_1_last: egen diff_candidates = nvals(stes_id)
	egen total_candidates = nvals(stes_id) if isco_08_1_last!=.
	gen pct_candidates_isco = diff_candidates/total_candidates*100
	fcollapse pct_candidates_isco , by(isco_08_1_last)
	rename isco_08_1_last isco_08_1
	tabstat pct_candidates_isco, by(isco_08_1)
	save "Misc_files\pct_candidates_isco.dta", replace
	restore
	* Searches by occupation 
	preserve
		recode s_isco_08_1 (.=0)
		bysort s_isco_08_1: egen diff_searches = nvals(search_tag)
		egen total_searches = nvals(search_tag) if s_isco_08_1!=.
		gen pct_searches_isco = diff_searches/total_searches*100
		bysort s_isco_08_1: egen diff_users = nvals(tracking_id) 
		fcollapse pct_searches_isco diff_users, by(s_isco_08_1) 
		egen 	group = group(pct_searches_isco s_isco_08_1)
		replace group = -group
		labmask group, values(s_isco_08_1) decode
		rename s_isco_08_1 isco_08_1
	merge 1:1 isco_08_1 using "Misc_files\pct_candidates_isco.dta"
		drop if isco_08_1==.
		drop if isco_08_1==0
		eststo clear
		eststo: quietly estpost tabstat diff_users, by(group) not
		eststo: quietly estpost tabstat pct_searches_isco, by(group) not
		eststo: quietly estpost tabstat pct_candidates_isco, by(group) not
		format pct_searches_isco %9.2f
		format pct_candidates_isco %9.2f
		format diff_users %12.0f
	* Gen tables
	esttab, cells(mean(fmt(%9.2g))) varwidth(20) gaps label varlabels(`e(labels)') nonumber noobs collabels(none) ///
			mtitle("\# recruiters" "\% searches" "\% candidates") ///
			title(Distribution of searches and candidates by occupation)	
	esttab using "$results_part_time/table_d3.tex", replace ///
			cells(mean(fmt(%9.2g))) varwidth(20) label varlabels(`e(labels)') nonumbers noobs gaps collabels(none) frag ///
			mtitle("\# recruiters" "\% searches" "\% candidates") ///
			title(Distribution of searches and candidates by occupation)	///
			addnotes("Source: SECO: Jobroom data")	
	restore

		
	****************************	
	****************************
	* With Sample restrictions
	****************************
	****************************	

	* Sample restrictions
	run "Help_files\sample_restrictions_parttime.do"
	
	cap gen in_results = search_tag!=.
		
	*****************************************
	* No of searches, recruiters, profile views, time on profile etc.
	*****************************************
			
	* Full sample: Number of searches and recruiters, profile views, etc.
	gen 	time_profile_topc = time_profile_until_click
	replace time_profile_topc = 120 if time_profile_topc>120 & time_profile_topc<. // Topcoding of outliers: More than 120 Sec.
	
	egen mean_time_profile_topc = mean(time_profile_topc)		// For the time on profile we take the overall average (hence it is a weighted (with number of results in search list) average	
	egen n_diff_users 			= nvals(tracking_id)		
	egen n_diff_jobseekers		= nvals(stes_id)
	egen n_diff_search 			= nvals(search_tag)
	egen n_in_results			= total(in_results)
	egen n_profile_view			= total(click_candidate)
	egen n_contact				= total(contact_button_clicked)			//  1,795,109
	quietly estpost sum  n_diff_users n_diff_jobseekers n_diff_search n_in_results n_profile_view n_contact mean_time_profile_topc
	eststo descr_recr
	
	label var n_diff_users 	"Users (recruiters)"
	label var n_diff_jobseekers "Jobseekers"
	label var n_diff_search "Search requests"
	label var n_in_results	"Jobseeker entries on result lists"
	label var n_profile_view "Profile views"
	label var n_contact		"Contact attempts"
	label var mean_time_profile_topc "Time on profile until first click (in sec.)*"

	esttab descr_recr ,  ///
		keep(n_diff_users n_diff_search n_diff_jobseekers n_in_results n_profile_view n_contact mean_time_profile_topc) ///
		cells(mean(fmt(%12.2gc))) varwidth(30) label collabels(none)  noobs ///
		title(Descriptive stats about users and searches, March - December 2017) ///
		addnote("Source: Seco Jobroom data")
		
	* -> Some of these numbers appear in Table D.1 column 1
	
	****************************	
	* Recode and rename variables
	****************************

	gen 	workvolume_det_cat=0 if workvolume==100
	replace workvolume_det_cat=1 if inrange(workvolume,90,99)
	replace workvolume_det_cat=2 if inrange(workvolume,80,89)
	replace workvolume_det_cat=3 if inrange(workvolume,70,79)
	replace workvolume_det_cat=4 if inrange(workvolume,60,69)
	replace workvolume_det_cat=5 if inrange(workvolume,50,59)
	replace	workvolume_det_cat=6 if workvolume<50
		
	label var af_Sonn_Feiertagsarbeit "Work on Sundays and public holidays"
	label var af_Schichtarbeit "Shift work"
	label var af_Nachtarbeit "Night work"
	label var af_Heimarbeit "Work from home"

	label define cod_zivilstand_engl 1 "Unmarried" 2 "Married" 3 "Widowed" 4 "Divorced"
	label values cod_zivilstand cod_zivilstand_engl
		
	gen married = cod_zivilstand==2

	gen 	nation_kat_short_new = .
	replace nation_kat_short_new = 0 if nation_kat==0
	replace nation_kat_short_new = 1 if inrange(nation_kat,1,9)
	label define nation_kat_s_lab 0 "Swiss citizen" 1 "Foreigner" 
	label values nation_kat_short_new nation_kat_s_lab 
	

	************************************************************
	* Descrptive Stats by gender and part-/fulltime status: Supply side
	************************************************************

	***************************
	* Willingness to work part-/full-time by gender
	***************************

	gen 	workvolume_very_det_cat = 100 if workvolume==100
	replace workvolume_very_det_cat = 90 if inrange(workvolume,90,99) 
	replace workvolume_very_det_cat = 80 if inrange(workvolume,80,89)
	replace workvolume_very_det_cat = 70 if inrange(workvolume,70,79)
	replace workvolume_very_det_cat = 60 if inrange(workvolume,60,69)
	replace workvolume_very_det_cat = 50 if inrange(workvolume,50,59)
	replace	workvolume_very_det_cat = 40 if inrange(workvolume,40,49)
	replace	workvolume_very_det_cat = 30 if inrange(workvolume,30,39)
	replace	workvolume_very_det_cat = 20 if inrange(workvolume,20,29)
	replace	workvolume_very_det_cat = 10 if inrange(workvolume,5,19)

	sort stes_id date		
	preserve
	fcollapse (first) workvolume_very_det_cat geschlecht, by(stes_id)		
	histogram workvolume_very_det_cat if geschlecht==0, 	percent discrete fcolor(black) lcolor(white) ///
							ylabel(, format(%4.0fc)) ///							
							xlabel(10(10)100)  ///
							xtitle(Desired working hours (in FTE), margin(medsmall) size(medlarge)) ///
							ytitle(Share of jobseekers (in percent), margin(medsmall) size(medlarge)) ///
							graphregion(color(white)) bgcolor(white)  addlabels addlabopts(yvarformat(%4.1fc) mlabsize(medsmall))			
	graph export "$results_part_time/figure_d2_men.eps" , as(eps) replace				
				
	histogram workvolume_very_det_cat if geschlecht==1, 	percent discrete fcolor(gs10) lcolor(white) ///
							ylabel(, format(%4.0fc)) ///							
							xlabel(10(10)100)  ///
							ylabel(0(20)100)  ///			
							xtitle(Desired working hours (in FTE), margin(medsmall) size(medlarge)) ///
							ytitle(Share of jobseekers (in percent), margin(medsmall) size(medlarge)) ///
							graphregion(color(white)) bgcolor(white)  addlabels addlabopts(yvarformat(%4.1fc) mlabsize(medsmall))			
	graph export "$results_part_time/figure_d2_women.eps" , as(eps) replace					
	restore

	
	***************************
	* Sava dataset with willingness to work part-/full-time by Isco-2 level and gender
	***************************

	levelsof workvolume_cat, local(levels_workvolume)
	foreach u of local levels_workvolume {
	gen workvolume_cat_`u' 	= workvolume_cat== `u'
	}
	
	preserve 
	recode s_isco_08_2 (.=99) 						// we recode missing values as 99, otherwise we loose too many observations
	
	collapse fulltime = workvolume_cat_1, by(s_isco_08_2 geschlecht) 
	replace fulltime = fulltime*100
	drop if s_isco_08_2==80
	
	cap run "Help_files\label_isco08_2_99_no_inform.do"
	label values s_isco_08_2 isco08_2_new99_lab

	reshape wide fulltime, i(s_isco_08_2) j(geschlecht)	
				
	save "Misc_files\share_seeking_fulltime_gender_isco2.dta", replace	
	restore


	***************************
	* How many unemployed change from part-time to full-time and vice versa during unemployment spell?
	***************************
	
	bysort stes_id: egen max_workvolume_very_det = max(workvolume_very_det_cat)		// we have no missings in workvolume_very_det_cat
	bysort stes_id: egen min_workvolume_very_det = min(workvolume_very_det_cat)
	gen change_part_full = max_workvolume_very_det!=min_workvolume_very_det
		
	bysort stes_id (date): gen n_stes = _n
	tab change_part_full									if n_stes==1 ,m		// 3'901 change their stated preference for part-/full-time
	tab change_part_full geschlecht							if n_stes==1 ,m		// 1'184 men and 2'717 women
	tab change_part_full 				if geschlecht==0	&  n_stes==1 ,m		// 0.65% of all men change
	tab change_part_full 				if geschlecht==1	&  n_stes==1 ,m		// 2.06% of all women change
	
		
	************************************************************
	* Descrptive Stats by gender and full- parttime: Visible job seeker characteristics
	************************************************************
		
	cap drop mode_cod_erfa_searched
	bys stes_id: egen mode_cod_erfa_searched = mode(cod_erfa_searched), maxmode
	
	set more off
	foreach v in  workvolume_cat education_isced mobility_no_cantons cod_zivilstand mode_cod_erfa_searched has_skills registration_time verfuegbar no_diff_prof bn2000_1_last af_Sonn_Feiertagsarbeit af_Schichtarbeit af_Nachtarbeit af_Heimarbeit {
		local l`v' : variable label `v'
	 } 
	levelsof education_isced, local(lab_edu)
	foreach x of local lab_edu {
	local lab_edu_`x' : label education_isced `x'
	local quad = "\quad"
	local lab_edu_`x' : list quad | lab_edu_`x'
	di " `lab_edu_`x'' "
	}  
	levelsof mode_cod_erfa_searched, local(lab_erfa)
	foreach z of local lab_erfa {
	local lab_erfa_`z' : label s_experience_lab `z'
	local quad = "\quad"
	local lab_erfa_`z' : list quad | lab_erfa_`z'
	di " `lab_erfa_`z'' "
	}
	levelsof cod_zivilstand, local(lab_zivil)
	foreach o of local lab_zivil {
	local lab_zivil_`o' : label cod_zivilstand_engl `o'
	local quad = "\quad"
	local lab_zivil_`o' : list quad | lab_zivil_`o' 
	di " `lab_zivil_`o'' "
	}
	levelsof nation_kat_short_new, local(lab_nat)
	foreach i of local lab_nat {
	local lab_nat_`i' : label nation_kat_s_lab `i'
	di " `lab_nat_`i'' "
	}
	levelsof workvolume_cat, local(lab_workvolume)
	foreach u of local lab_workvolume {
	local lab_workvolume_`u' : label s_workload_cat_lab `u'
	local quad = "\quad"
	local lab_workvolume_`u' : list quad | lab_workvolume_`u' 
	di " `lab_workvolume_`u'' "
	}
	
	sort stes_id timestamp
	
	eststo clear
	preserve
	collapse  (first)  geschlecht married alter no_diff_prof	registration_time 	fulltime workvolume_cat mobility_no_cantons  mode_cod_erfa_searched education_isced has_skills skill_softskills_general skill_it_skills_general_general skill_it_skills_deep_general verfuegbar fyn_geschuetzt_kontaktangaben  nation_kat_short_new   cod_zivilstand af_Sonn_Feiertagsarbeit af_Schichtarbeit af_Nachtarbeit af_Heimarbeit l_German l_CH_German l_English l_French l_Italian bn2000_1_last, by(stes_id)
	foreach v in 	 fulltime workvolume_cat mobility_no_cantons  mode_cod_erfa_searched education_isced has_skills skill_softskills_general skill_it_skills_general_general skill_it_skills_deep_general verfuegbar fyn_geschuetzt_kontaktangaben  nation_kat_short_new cod_zivilstand af_Sonn_Feiertagsarbeit af_Schichtarbeit af_Nachtarbeit af_Heimarbeit l_German l_CH_German l_English l_French l_Italian bn2000_1_last {
	label var `v' "`l`v''"
	}
	label var geschlecht "Share female"
	label var married "Share married"
	label var alter "Age"
	label var no_diff_prof "Occup. mobility (No of occupations)" 
	label var mobility_no_cantons "Regional mobility (No of cantons)"
	label var registration_time "Unemployment duration (in days)"
	recode verfuegbar (99=.)
	label var verfuegbar "Share immediately available" 
	label var fyn_geschuetzt_kontaktangaben "Contact information visible"
	label var l_German "\quad Very good German skills" 
	label var l_CH_German "\quad Very good Swiss German skills" 
	label var l_English "\quad Very good English skills" 
	label var l_French "\quad Very good French skills" 
	label var l_Italian "\quad Very good Italian skills" 
	label var has_skills "\quad Share that specified skills"
	label var skill_softskills_general "\quad Softskills" 
	label var skill_it_skills_general_general "\quad General IT skills" 
	label var skill_it_skills_deep_general "\quad Special IT skills" 
	label var af_Sonn_Feiertagsarbeit "\quad Work on Sundays and public holidays"
	label var af_Schichtarbeit "\quad Shift work"
	label var af_Nachtarbeit "\quad Night work"
	label var af_Heimarbeit "\quad Work from home"

	label drop nation_kat_s_lab
	label define nation_kat_s_lab 0 "Swiss citizen" 1 "Foreigner" 
	label values nation_kat_short_new nation_kat_s_lab 

	levelsof education_isced, local(levels_edu)
	foreach x of local levels_edu {
	gen education_isced_`x' = education_isced==`x'
	label var education_isced_`x' " `lab_edu_`x'' "
	}
	levelsof bn2000_1_last, local(lab_bn)
	foreach y of local lab_bn {
	gen bn2000_1_last_`y' = bn2000_1_last==`y'
	}
	label var bn2000_1_last_1 "\quad  Agriculture and forestry"
	label var bn2000_1_last_2 "\quad  Manufacturing and craft"
	label var bn2000_1_last_3 "\quad  IT"
	label var bn2000_1_last_4 "\quad  Construction"
	label var bn2000_1_last_5 "\quad  Trade and transport"
	label var bn2000_1_last_6 "\quad  Hotel/restaurant, personal services"
	label var bn2000_1_last_7 "\quad  Management, finance, law"
	label var bn2000_1_last_8 "\quad  Education, health, arts"
	label var bn2000_1_last_9 "\quad  Unclassified"
	
	levelsof mode_cod_erfa_searched, local(levels_erfa)
	foreach z of local levels_erfa {
	gen erfa_`z' 		= mode_cod_erfa_searched==`z'
	label var erfa_`z'  " `lab_erfa_`z'' "
	}
	levelsof cod_zivilstand, local(levels_zivil)
	foreach o of local levels_zivil {
	gen cod_zivil_`o' 	= cod_zivilstand== `o'
	label var cod_zivil_`o' " `lab_zivil_`o'' "
	}
	levelsof nation_kat_short_new, local(levels_nat)
	foreach i of local levels_nat {
	gen nation_kat_`i' 	= nation_kat_short_new== `i'
	label var nation_kat_`i' " `lab_nat_`i'' "
	}
	levelsof workvolume_cat, local(levels_workvolume)
	foreach u of local levels_workvolume {
	gen workvolume_cat_`u' 	= workvolume_cat== `u'
	label var workvolume_cat_`u' " `lab_workvolume_`u'' "
	}
	
	local education_isced "education_isced_999 education_isced_1 education_isced_2 education_isced_3 education_isced_6 education_isced_7 education_isced_8"
	
	*******************
	* Create Table with job seeker characteristics for men and women separately
	******************
	* Fulltime men
	quietly estpost sum  no_diff_prof mobility_no_cantons nation_kat_0  `education_isced' erfa_*  l_German l_CH_German l_English l_French l_Italian    bn2000_1_last_* if geschlecht==0 & fulltime==1
	eststo fulltime_men_char
	* Parttime men 
	quietly estpost sum  no_diff_prof mobility_no_cantons nation_kat_0  `education_isced' erfa_*  l_German  l_CH_German l_English l_French l_Italian   bn2000_1_last_* if geschlecht==0 & fulltime==0
	eststo parttime_men_char
	* Difference men
	quietly estpost ttest no_diff_prof mobility_no_cantons nation_kat_0  `education_isced' erfa_*  l_German  l_CH_German l_English l_French l_Italian   bn2000_1_last_* if geschlecht==0, by(fulltime)
	eststo diff_men_char
	* Fulltime Women
	quietly estpost sum  no_diff_prof mobility_no_cantons nation_kat_0  `education_isced' erfa_*  l_German  l_CH_German l_English l_French l_Italian   bn2000_1_last_* if geschlecht==1 & fulltime==1
	eststo fulltime_women_char
	* Parttime Women 
	quietly estpost sum  no_diff_prof mobility_no_cantons nation_kat_0  `education_isced' erfa_*  l_German  l_CH_German l_English l_French l_Italian   bn2000_1_last_* if geschlecht==1 & fulltime==0
	eststo parttime_women_char
	* Difference Women
	quietly estpost ttest no_diff_prof mobility_no_cantons  nation_kat_0  `education_isced' erfa_*  l_German  l_CH_German l_English l_French l_Italian   bn2000_1_last_* if geschlecht==1, by(fulltime)
	eststo diff_women_char

	esttab fulltime_women_char parttime_women_char diff_women_char fulltime_men_char parttime_men_char diff_men_char, cells("mean(pattern(1 1 0 1 1 0) fmt(%9.2gc)) b(star pattern(0 0 1 0 0 1) fmt(%9.2gc))")  label   ///
			mgroups("\textbf{Women}" "\textbf{Men}", pattern(1 0 0 1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(})) ///
			mtitle("Full-time" "Part-time" "Difference" "Full-time" "Part-time" "Difference" )  collabels(none) ///
			keep( nation_kat_0 no_diff_prof mobility_no_cantons  "\textit{Work experience}" erfa_*  "\textit{Education}" `education_isced' "\textit{Language skills}" l_German l_CH_German l_English l_French l_Italian  "\textit{Occup. last job}" bn2000_1_last_* ) ///	
			order(nation_kat_0 no_diff_prof mobility_no_cantons  "\textit{Work experience}" erfa_* "\textit{Education}" `education_isced'  "\textit{Language skills}" l_German l_CH_German l_English l_French l_Italian "\textit{Occup. last job}" bn2000_1_last_* ) ///	
			title(Candidate characteristics by gender)
	
	esttab fulltime_women_char parttime_women_char diff_women_char fulltime_men_char parttime_men_char diff_men_char using "$results_part_time/table_d5.tex", replace ///
			cells("mean(pattern(1 1 0 1 1 0) fmt(%9.2gc)) b(star pattern(0 0 1 0 0 1) fmt(%9.2gc))")  label  frag  ///
			mgroups("\textbf{Women}" "\textbf{Men}", pattern(1 0 0 1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(})) ///
			mtitle("Full-time" "Part-time" "Difference" "Full-time" "Part-time" "Difference" )  collabels(none) ///
			keep( nation_kat_0 no_diff_prof mobility_no_cantons  "\textit{Work experience}" erfa_*  "\textit{Education}" `education_isced' "\textit{Language skills}" l_German l_CH_German l_English l_French l_Italian  "\textit{Occup. last job}" bn2000_1_last_* ) ///	
			order( nation_kat_0 no_diff_prof mobility_no_cantons  "\textit{Work experience}" erfa_* "\textit{Education}" `education_isced'  "\textit{Language skills}" l_German l_CH_German l_English l_French l_Italian "\textit{Occup. last job}" bn2000_1_last_* ) ///	
			title(Candidate characteristics by Full-time/Part-time and gender \label{tab:DescrCandFullParttimeShort}) ///
			addnote("Source: Seco Jobroom data")
	restore
		
	***********
	* Human-capital index by full-time / part-time and gender split
	***********	
	
	preserve
	fcollapse (last)  geschlecht married alter no_diff_prof	registration_time 	workvolume_cat mobility_no_cantons  cod_erfa_searched  has_skills    cod_zivilstand af_Sonn_Feiertagsarbeit af_Schichtarbeit af_Nachtarbeit af_Heimarbeit , by(stes_id)

	tab workvolume_cat,nol
	
	merge 1:1 stes_id  using "Misc_files\key_human_parttime_isco_new_stes.dta" , keepusing(mean_xb_hc_index_isco)
	drop if _merge==2
	drop _merge
	
	count if mean_xb_hc_index_isco==. // 39,718 - These are stes that appear only in the the training sample
	
	rename mean_xb_hc_index_isco humancap_index
		
	su humancap_index if geschlecht==0 & workvolume_cat==1
	local mean_fulltime `r(mean)'
	su humancap_index if geschlecht==0 & inrange(workvolume_cat,2,3)
	local mean_parttime `r(mean)'
	
	gen	 	humancap_index_temp=humancap_index											// for the figure, we set values below 0 to 0 and values above 1 to 1
	replace humancap_index_temp=1 if humancap_index_temp>1 & humancap_index_temp!=.
	replace humancap_index_temp=0 if humancap_index_temp<0

	twoway 	(kdensity humancap_index_temp if geschlecht==0 & workvolume_cat==1, lcolor(black) lpa(dash) ) || ///
			(kdensity humancap_index_temp if geschlecht==0 & inrange(workvolume_cat,2,3), lcolor(gs10))  ,  ///
			legend(lab(1 Full-time) lab(2 Part-time)) xli(`mean_fulltime',  lcolor(black) lpa(dash)) xli(`mean_parttime',  lcolor(gs10)) ///
			xtitle(Human capital index) ytitle(kdensity) graphregion(color(white)) bgcolor(white)  	
	graph export "$results_part_time\figure_d3_a.eps" , as(eps) replace	
	drop humancap_index_temp
	
	su humancap_index if geschlecht==1 & workvolume_cat==1
	local mean_fulltime `r(mean)'
	su humancap_index if geschlecht==1 & inrange(workvolume_cat,2,3)
	local mean_parttime `r(mean)'
	
	gen	 	humancap_index_temp=humancap_index											// for the figure, we set values below 0 to 0 and values above 1 to 1
	replace humancap_index_temp=1 if humancap_index_temp>1 & humancap_index_temp!=.
	replace humancap_index_temp=0 if humancap_index_temp<0
	
	twoway 	(kdensity humancap_index_temp if geschlecht==1 & workvolume_cat==1, lcolor(black) lpa(dash) ) || ///
			(kdensity humancap_index_temp if geschlecht==1 & inrange(workvolume_cat,2,3), lcolor(gs10)  )  ,  ///
			legend(lab(1 Full-time) lab(2 Part-time)) xli(`mean_fulltime',  lcolor(black) lpa(dash)) xli(`mean_parttime',  lcolor(gs10)) ///
			xtitle(Human capital index) ytitle(kdensity) graphregion(color(white)) 
	graph export "$results_part_time\figure_d3_b.eps" , as(eps) replace		
	drop humancap_index_temp
	restore
	

	***********
	***********
	* Gen table with descriptive statistics of characteristics that are not visible to recruiters on Job-Room
	***********
	***********
	
	sum versich_verdienst, d 
	gen 	versich_verdienst_no0 = versich_verdienst
	replace versich_verdienst_no0 = . if versich_verdienst==0
	replace versich_verdienst_no0 = versich_verdienst_no0*1000
		
	* Gen versich_verdienst adjusted for FTE (we assume that workers have worked the same number of hours as they are now looking for)
	gen 	versich_verdienst_no0_adj = versich_verdienst_no0/num_vermittlungs_grad*100	
	
	sum versich_verdienst_no0_adj if fulltime==1,d		// mean:   5583.607
	sum versich_verdienst_no0_adj if fulltime==0,d		// mean:   5767.771
	
	* Winsorize outliers: Very high and very low values
	* Values above 12,350 CHF per month are considered as outliers since this is the value of the maximum insured earnings 
	
	replace versich_verdienst_no0_adj  	= 12350 if versich_verdienst_no0_adj>12350   & versich_verdienst_no0_adj!=.
	
	* Following the Swiss Statistical Office (2019: Analyse der Lohnunterschiede zwischen Frauen und Männern anhand der Schweizerischen Lohnstrukturerhebung (LSE)), ///
	* Values below 2125 CHF per month (1/3 median wage) are considered as outliers   
	
	* We winsorize the wage at 2125 CHF per month
	replace versich_verdienst_no0_adj  = 2125 if versich_verdienst_no0_adj<2125  	
	
	sum versich_verdienst_no0_adj if fulltime==1,d		// mean:   5611.241
	sum versich_verdienst_no0_adj if fulltime==0,d		// mean:   5712.072

	sum versich_verdienst_no0_adj if fulltime==1 & geschlecht==0 ,d		// mean men:   5694.961
	sum versich_verdienst_no0_adj if fulltime==0 & geschlecht==0 ,d		// mean men:   5978.338	

	* Only 90% part-time jobseekers vs. full-time, adjusted 
	sum versich_verdienst_no0_adj 	if fulltime==0 & geschlecht==0 & workvolume_det_cat==1		// mean:    6021.536
	
	*******************
	* Create Table 
	******************
	
	label var versich_verdienst_no0_adj "Insured monthly earnings adj."
	
	sort stes_id timestamp
	eststo clear
	preserve
	collapse (mean)  versich_verdienst_no0_adj  alter (first)   geschlecht fulltime    , by(stes_id)

	save "Misc_files\earnings_age_unobserved.dta", replace	
	restore
	